# TD Stanley confirmed that we need to use partial r
source(here::here("code/load.R"))

here("data/meta_analyses_raw/AskDouPal2021/US Aid Allocations and Democracy MRA August 5 2021.dta") |>
  read_dta() |> 
  mutate(meta_id = "AskDouPal2021",
           subfield = "PE",
           question = "Does democracy and human rights record affect US aid allocation?",
           iv = case_when(HumanRights1yes == 1 ~ "human_rights",
                          Democracy1yes_ == 1 ~ "democracy"),
           overall_effect = "yes") |>
  #lots of rows have 2/3 of coefficient, SE, and tstat.
  #the following fills in the NAs using the remaining data.
  # mutate(SE = if_else(is.na(SE),
  #                abs(Signcorrectedcoefficient / tstat),
  #                SE)) |>
  # mutate(Signcorrectedcoefficient = if_else(
  #           is.na(Signcorrectedcoefficient),
  #           SE * tstat,
  #           Signcorrectedcoefficient)) |>
  select(meta_id,
         question,
         subfield,
         study_id = Authors,
         study_year = PublicationYear,
         estimate = PartialCorrelationr,
         std.error = SEforr,
         iv,
         overall_effect) |>
  filter(!is.na(iv)) |>
    write_csv(here("data/meta_analyses_clean/AskDouPal2021.csv"))
  
